<script type="text/javascript" src="${resource(dir:'/photobox',file:'ajaxfileupload.js')}"></script>
<script>
    $(function(){
        $("#UploadButton").click(function () {
            if ($("#file").val().length > 0) {
                ajaxFileUpload();
            }
            else {
                alert("请选择图片");
            }
        })
    });
    function ajaxFileUpload() {
        $.ajaxFileUpload
        (
                {
                    url:"<g:createLink controller="mngPublicizeImg" action="savePhoto"/>", //用于文件上传的服务器端请求地址
                    secureuri: false, //一般设置为false
                    fileElementId: 'file', //文件上传空间的id属性  <input type="file" id="file" name="file" />
                    dataType: 'JSON', //返回值类型 一般设置为json
                    success: function (data, status)  //服务器成功响应处理函数
                    {
                        $("#photoId").attr("src", '../'+ data.img)
                        $("#form-photoPath").val(data.img)
                        $("#img1").attr("src", data);
                        if (typeof (data.error) != 'undefined') {
                            if (data.error != '') {
                                alert(data.error);
                            } else {
                                alert(data.msg);
                            }
                        }
                    },
                    error: function (data, status, e)//服务器响应失败处理函数
                    {
                        alert(e);
                    }
                }
        );
        return false;
    }
</script>
<div class="row">
    <div class="col-xs-12">
        <g:form id="form" useToken="true" url="${url}" class="form-horizontal" role="form">
            <input type="hidden" class="input-value" name="id"  value="${publicizeImg?.id}"/>
            <div class="form-group  message alert">

            </div>
            <div class="form-group form-field field-name">
                <label class="col-sm-3 control-label no-padding-right" for="form-name"> 名称: </label>
                <div class="col-xs-12 col-sm-4">
                    <g:textField  name="name" id="form-name" value="${publicizeImg?.name}" placeholder="输入名称" class="width-100" />
                </div>
                <div class="help-block col-xs-12 col-sm-reset inline fieldMsg">  </div>
            </div>

            <div class="form-group form-field field-photoPath">
                <div style="text-align:center;" >
                    <g:if test="${imagePath}">
                        <img width="800" height="600"  id="photoId" src="${imagePath}" />
                    </g:if>
                </div>
                <label class="col-sm-3 control-label no-padding-right" for="form-photoPath"> 图片路径: </label>
                <div class="col-xs-12 col-sm-4">
                    <input type="text"   name="photoPath" id="form-photoPath" value="${publicizeImg?.photoPath}"  />
                    <p><input type="file" id="file" name="file" /></p>
                    <p><input id="UploadButton" type="button" value="上传" class="tishi_btn2" /></p>
                </div>
                <div class="help-block col-xs-12 col-sm-reset inline fieldMsg">  </div>
            </div>

            <div class="form-group form-field field-linkurl">
                <label class="col-sm-3 control-label no-padding-right" for="form-linkurl"> 链接路径: </label>
                <div class="col-xs-12 col-sm-4">
                    <g:textField   name="linkurl" id="form-linkurl" value="${publicizeImg?.linkurl}" placeholder="链接路径" class="width-100" />
                </div>
                <div class="help-block col-xs-12 col-sm-reset inline fieldMsg">  </div>
            </div>
            %{--<div class="form-group form-field field-location">--}%
                %{--<label class="col-sm-3 control-label no-padding-right" for="form-location"> 位置: </label>--}%
                %{--<div class="col-xs-12 col-sm-4">--}%
                    %{--<g:select name="location" id="form-location" from="${_location}" optionKey="id" optionValue="text" value="${publicizeImg?.location}"></g:select>--}%
                %{--</div>--}%
                %{--<div class="help-block col-xs-12 col-sm-reset inline fieldMsg">  </div>--}%
            %{--</div>--}%
            <div class="form-group form-field field-isShow">
                <label class="col-sm-3 control-label no-padding-right" for="form-isShow"> 显示: </label>
                <div class="col-xs-12 col-sm-4">
                    <g:checkBox name="isShow" id="form-isShow" value="${publicizeImg?.isShow}" ></g:checkBox>
                </div>
                <div class="help-block col-xs-12 col-sm-reset inline fieldMsg">  </div>
            </div>

            <div class="clearfix form-actions">
                <div class="col-md-offset-3 col-md-9">
                    <button class="btn btn-info" type="submit">
                        <i class="icon-ok bigger-110"></i>
                        提交
                    </button>

                    &nbsp; &nbsp; &nbsp;
                    <button class="btn" type="reset">
                        <i class="icon-undo bigger-110"></i>
                        重置
                    </button>
                </div>
            </div>
        </g:form>
    </div>
</div>
<r:require module="mng_form"></r:require>
<r:script>

        (function($) {
            $(".selectPicker").selectPicker({
                width: 700, height: 500
            });
            $(".chosen-select").chosen();
            $('#form').ajaxForm({
                beforeSubmit: function() {
                    $("#form").jqFormClearErr();
                    $("#form").find("input[type=submit]").attr("disabled", true);
                },
                success: function(response) {
                    $("#form").find("input[type=submit]").attr("disabled", false);
                    $("#form").jqFormResponse({
                        response: response,
                        successUri: "<g:createLink />"
                    });

                },
                error: function() {
                    $("#form").find("input[type=submit]").attr("disabled", false);
                }
            });
        }(jQuery));


</r:script>